﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using EFmodel;
using IEFbll;
using IEFdal;

namespace EFbll
{
    public partial class UserService : BaseService<User>, IUserService
    {
        private IUserDAL UserDAL = EFdalContainer.Container.Resolve<IUserDAL>();
        public override void SetDal()
        {
            Dal = UserDAL;
        }
    }
    public partial class RoleService : BaseService<Role>, IRoleService
    {
        private IRoleDAL RoleDAL = EFdalContainer.Container.Resolve<IRoleDAL>();
        public override void SetDal()
        {
            Dal = RoleDAL;
        }
    }
    public partial class LoginService : BaseService<User>, ILoginService
    {
        private ILoginDAL LoginDAL = EFdalContainer.Container.Resolve<ILoginDAL>();

        public override void SetDal()
        {
            Dal = LoginDAL;
        }
        /// <summary>
        /// 验证登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>验证成功返回true，验证失败返回false</returns>
        public bool LoginOK(string userName, string password)
        {
            userName = userName.Trim();
            using( var dbContext = new WTDbContext() )
            {
                User userTemp;
                userTemp = dbContext.User.FirstOrDefault( u => u.UserName == userName && u.Password == password && u.IsUsed && !u.IsDel );
                if( userTemp != null )
                {
                    return true;
                }
                return false;
            }
        }
    }
}
